import * as express from 'express';
import * as fs from 'fs';
var cors = require('cors')
//const $ = require('jQuery');

const app = express();
app.use(express.static('public'));
app.get('/login.html',function (req,res) {
    res.sendFile( __dirname + "/" + "login.html" );
});
app.get('/user/:id', cors(), function (req, res, next) {
    res.json({msg: 'This is CORS-enabled for a Single Route'})
});
app.get('/user/list', function (req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    fs.readFile( __dirname + "/" + "users.json", 'utf8', function (err, data) {
        res.end( data );
    });
});

app.listen(3000, 'localhost', () => {
    console.log(`express服务已经启动:localhost:3000`);
});